package kerjodando.casper.util;

import java.io.File;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.ConsoleHandler;
import java.util.logging.SimpleFormatter;

import net.nutss.Control;

public class ConfigUtil {
	public final static String WORKINGPATH = System.getProperty("user.dir")
			+ "/"+ConstantUtil.APPLICATION+"/";
	public final static String LOGPATH = WORKINGPATH + "logger/";

	public static void setup() {
		makeDirectory(LOGPATH);
		Control.log.setLevel(Level.ALL);
		Control.log.addHandler(new ConsoleHandler());
		FileHandler fh = null;
		try {
			fh = new FileHandler(LOGPATH+"stunt.log", 16 * ConstantUtil.MBYTES, 1);
			fh.setFormatter(new SimpleFormatter());	
			Control.log.addHandler(fh);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	static private void makeDirectory(String sPath) {
		File cpf = new File(sPath);
		if (cpf.exists()) {
			if (cpf.isDirectory()) {
				return;
			} else {
				cpf.delete();
			}
		}
		cpf.mkdir();
	}

}
